using System;
using System.Collections.Generic;

namespace LiJ.Common.Core
{
	/// <summary>
	/// 分页实体扩展
	/// </summary>
	public static class PageListMoMap
	{
		/// <summary>
		///   转化pageList列表实体
		/// </summary>
		/// <typeparam name="TPara"></typeparam>
		/// <typeparam name="TResult"></typeparam>
		/// <param name="pageList"></param>
		/// <param name="convertFun"></param>
		/// <returns></returns>
		public static PageListMo<TResult> ConvertToPageList<TPara, TResult>(this PageListMo<TPara> pageList, Func<TPara, TResult> convertFun) where TPara : class, new()where TResult : class, new()
		{
			if (convertFun == null)
			{
				throw new ArgumentNullException("convertFun", "转化方法不能为空！");
			}
			List<TResult> list = null;
			if (pageList.Data != null)
			{
				list = pageList.Data.ConvertAll(e => convertFun(e));
			}
			return new PageListMo<TResult>(pageList.Total, list);
		}
	}
}
